﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static System.Math;

namespace ConvSizeCalculate
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        int output_h = 0;
        int output_w = 0;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Calculate_Click(object sender, RoutedEventArgs e)
        {
            int nh = Convert.ToInt32(input_h.Text);
            int nw = Convert.ToInt32(input_w.Text);
            int k = Convert.ToInt32(kernel.Text);
            int p = Convert.ToInt32(padding.Text);
            int s = Convert.ToInt32(stride.Text);
            if (!(bool)Transpose.IsChecked)
            {
                if (s == 0)
                {
                    output_h = (nh - k + 2 * p + 1);
                    output_w = (nw - k + 2 * p + 1);
                }
                else
                {
                    double h = (nh - k + 2 * p + s) / s;
                    double w = (nw - k + 2 * p + s) / s;
                    output_h = Convert.ToInt32(Floor(h));
                    output_w = Convert.ToInt32(Floor(w));
                }
            }
            else
            {
                output_h = (nh - 1) * s - 2 * p + k;
                output_w = (nw - 1) * s - 2 * p + k;
            }

            output.Text = output_h.ToString() + " x " + output_w.ToString();
        }

        private void AsInput_Click(object sender, RoutedEventArgs e)
        {
            input_h.Text = output_h.ToString();
            input_w.Text = output_w.ToString();
        }
    }
}
